/**
* @author chenchen
*/

var Address = {
	addresses: [],
	
	showAddresses: function(responseText) {
		console.log(" " + responseText);
		console.log("11234");
		itemList = responseText.Addresses;
		for(var i=0;i<itemList.length;i++) {
			console.log("name " + itemList[i].name);
			console.log("addValue " + itemList[i].addressValue);
			console.log("phone " + itemList[i].phone);
			console.log("postcode " + itemList[i].postCode);
			console.log("addressID " + itemList[i].addressID);
			var addressTr = dojo.doc.createElement("tr");
			var label = dojo.doc.createElement("td");
			label.innerHTML = i+1;
			label.width = "5%";
			var nameTd = dojo.doc.createElement("td");
			nameTd.innerHTML = "收件人： " + itemList[i].name;
			nameTd.width = "20%";
			var addValueTd = dojo.doc.createElement("td");
			addValueTd.innerHTML = "地址： " + itemList[i].addressValue;
			addValueTd.width = "20%";
			var phone = dojo.doc.createElement("td");
			phone.innerHTML = "电话： " +　itemList[i].phone;
			phone.width = "20%";
			var postcode = dojo.doc.createElement("td");
			postcode.innerHTML = "邮编： " + itemList[i].postCode;
			postcode.width = "20%";
			var edit = dojo.doc.createElement("td");
			edit.innerHTML = "<a href='#'>修改</a>";
			var drop = dojo.doc.createElement("td");
			drop.innerHTML = "<a href='#'>删除</a>";
			addressTr.appendChild(label);
			addressTr.appendChild(nameTd);
			addressTr.appendChild(addValueTd);
			addressTr.appendChild(phone);
			addressTr.appendChild(postcode);
			addressTr.appendChild(edit);
			addressTr.appendChild(drop);
			dojo.byId("addresses").appendChild(addressTr);
		}
	},
	
	loadAddresses: function() {
		console.log("enter call ajax");
		var kw = {
            url: "getAddressAction.do",
            handleAs: "json",
            preventCache: true,
            load: this.showAddresses
        };
        dojo.xhrPost(kw);
	},
	
	deleteAddress: function(addressId) {
		
	}
};

console.log("include addresses");